/*******************************************
 * Copyright 2007 Aphrodite Framework for javaME .
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v2.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * Email : owner@aphroditeme.dev.java.net
 * Contributors:
 *     Kent Elton - initial API and implementation
 *******************************************/

package com.aphrodite.util.log;

/**
 * <p>
 * Allows you to append all log messages to a string
 * </p>
 * The log message can be retrieved using the <code>getBuffer()</code> method
 * 
 * @author kentelt
 * 
 */
public final class StringBufferAppender extends Appender {

	private static StringBufferAppender appender;
	private static StringBuffer buf = new StringBuffer();

	public static void clearBuffer() {
		buf = new StringBuffer();
	}

	public static StringBufferAppender getAppender() {
		if (appender == null) {
			appender = new StringBufferAppender();
		}
		return appender;
	}

	public static StringBuffer getBuffer() {
		return buf;
	}

	private StringBufferAppender() {
		super();
	}

	protected void error(StringBuffer message) {
		buf.append(message).append('\n');

	}

	protected void fatal(StringBuffer message) {
		buf.append(message).append('\n');

	}

	protected void info(StringBuffer message) {
		buf.append(message).append('\n');

	}

	protected void warn(StringBuffer message) {
		buf.append(message).append('\n');

	}

}
